package acwing._1_1AlgorithmBasic._5DynamicProgramming;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._5DynamicProgramming
 * @File : Q0902.java
 * @Author : WangRuoyu
 * @Date : 2023/4/6 16:14
 */

import java.io.*;

public class Q0902 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int m = Integer.parseInt(br.readLine().split(" ")[0]);
        String a = br.readLine();
        int n = Integer.parseInt(br.readLine().split(" ")[0]);
        String b = br.readLine();

        int[][] f = new int[m + 1][n + 1];
        for (int i = 0; i <= n; i++) f[0][i] = i;
        for (int i = 0; i <= m; i++) f[i][0] = i;

        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                f[i][j] = Math.min(f[i - 1][j], f[i][j - 1]) + 1;
                if (a.charAt(i - 1) == b.charAt(j - 1)) f[i][j] = Math.min(f[i][j], f[i - 1][j - 1]);
                else f[i][j] = Math.min(f[i][j], f[i - 1][j - 1] + 1);
            }
        }

        System.out.println(f[m][n]);
    }
}

